<template>
	<view class="drawercontent">
		<view @click="showDrawer">
			<view class="icon-shaixuan">筛选</view>
		</view>
		<uni-drawer ref="showLeft" :width="320" mode="right">
			<!-- <button @click="closeDrawer">关闭Drawer</button> -->
			<view class="formbox">
				<view class="h5">数据筛选</view>
				<uni-forms ref="form" :modelValue="formData">

					<view class="ul" v-if="type == 6.2">
						<view class="h6">行业类别</view>
						<uni-forms-item>
							<uni-data-picker :border="false" v-model="formData.industryCategory"
								:localdata="categoryList" popup-title="请行业类别"></uni-data-picker>
						</uni-forms-item>

					</view>
					<view class="ul"
						v-if="type == 3 || type == 5 || type == 5.1 || type == 6 || type == 6.1 || type == 6.2">
						<view class="h6">时间筛选（选择时间段）</view>
						<uni-forms-item>
							<uni-datetime-picker v-model="range" type="daterange" rangeSeparator="至" />
						</uni-forms-item>
					</view>
					<view class="ul" v-if="type == 6.2">
						<view class="h6">排查状态</view>
						<uni-forms-item>
							<myRadio type="radio" @change="changeCheckStatus" dictCode="check_status1" :isAll="true">
							</myRadio>
						</uni-forms-item>

					</view>
					<view class="ul" v-if="type == 6.2">
						<view class="h6">场所状态</view>
						<uni-forms-item>
							<myRadio type="radio" @change="changeplaceStatus" dictCode="place_status" :isAll="true">
							</myRadio>
						</uni-forms-item>

					</view>

					<view class="ul" v-if="type == 3">
						<view class="h6">隐患统计维度</view>
						<uni-forms-item>
							<myRadio :indexs="type == 3 ? 0 : -1" type="radio" @change="changedimension"
								dictCode="dimension">
							</myRadio>
						</uni-forms-item>
					</view>
					<view class="ul" v-if="type == 3 || type == 1 || type == 6 || type == 6.1">
						<view class="h6">隐患分级维度</view>
						<uni-forms-item>
							<myRadio type="radio" @change="changelevel" dictCode="danger_level" :isAll="true">
							</myRadio>
						</uni-forms-item>
					</view>
					<!-- <view class="ul" v-if="type == 6">
						<view class="h6">排查公司</view>
						<uni-forms-item>
							<myRadio type="radio" @change="changecompany" dictCode="danger_level" :isAll="true">
							</myRadio>
						</uni-forms-item>
					</view> -->
					<view class="ul" v-if="type == 1">
						<view class="h6">预审状态</view>
						<uni-forms-item>
							<myRadio type="radio" @change="changereviewStatus" dictCode="review_status" :isAll="true">
							</myRadio>
						</uni-forms-item>
					</view>
					<view class="ul" v-if="type == 3 || type == 5 || type == 6 || type == 6.1">
						<view class="h6">场所类别</view>
						<uni-forms-item>
							<myRadio :indexs="type == 3 ? 2 : type == 6 ? -1 : -1" type="radio"
								@change="changeplaceType" dictCode="place_type">
							</myRadio>
						</uni-forms-item>
					</view>
					<view class="ul"
						v-if=" type == 3 || type == 5 || type == 5.1 || type == 6 || type == 6.1 || type == 6.2">
						<view class="h6">所属社区</view>
						<uni-forms-item>
							<uni-data-picker :border="false" v-model="formData.community" :localdata="queryTreeList"
								:map="{text:'departName',value:'id'}" popup-title="请选择所属社区"></uni-data-picker>
						</uni-forms-item>
					</view>
				</uni-forms>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn lg bg-blue shadow" @tap="formSubmit">提交</button>
			</view>
			<!-- 			<view class="uni-btn-v">
				<button type="warn" @click="formSubmit">提交</button>
			</view> -->

		</uni-drawer>
	</view>
</template>
<script>
	import appSelect from '@/components/my-componets/appSelect.vue'
	import server from '@/api/server.js'
	const plan_type = [{
		text: '日常记录',
		value: '日常记录1'
	}, {
		text: '本周工作',
		value: '本周工作2'
	}, {
		text: '下周计划',
		value: '下周计划3'
	}];

	export default {
		props: {
			type: {
				type: Number,
				default () {
					return ''
				}
			},
		},
		components: {
			appSelect,
		},
		mounted() {},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				queryTreeList: [],
				showtrue: true,
				categoryList: [],
				range: ["", ""],
				formData: {
					dangerDesc: '', //搜索
					industryCategory: '', //行业选择
					status: '', //排查状态
					placeStatus: '', //场所状态
					level: '', //隐患分级维度
					reviewStatus: '', //预审状态
					placeType: '', //场所类别
					community: '', //所属社区
					startTime: '',
					endTime: '',
					dimension: '', //隐患统计维度
					company: '', //排查公司
				}
			};
		},
		mounted() {
			var aData = new Date();
			console.log(aData) //Wed Aug 21 2019 10:00:58 GMT+0800 (中国标准时间)
			this.value = aData.getFullYear() + "-" + (aData.getMonth() + 1) + "-" + aData.getDate();
			console.log(this.value) //2019-8-20 
			this.getdet()
		},
		watch: {
			range(newval) {
				this.formData.startTime = this.range[0]
				this.formData.endTime = this.range[1]
			},
		},
		methods: {
			showDrawer() {
				this.$refs["showLeft"].open();
				//行业类别
				server.categoryList().then(res => {
					this.$nextTick(function() {
						console.log(res)
						this.categoryList = res.data.result
					});

				})
			},
			formSubmit: function(e) {
				// console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
				// var formdata = JSON.stringify(e.detail.value)
				let obj = {}
				if (this.type == 3) {
					obj.text = this.formData.dangerDesc,
						obj.community = this.formData.community,
						obj.dimension = this.formData.dimension,
						obj.startTime = this.formData.startTime,
						obj.endTime = this.formData.endTime,
						obj.placeType = this.formData.placeType,
						obj.level = this.formData.level
					this.$emit('testShow', obj)
				} else if (this.type == 6) {
					obj.userName = this.formData.dangerDesc,
						obj.community = this.formData.community,
						obj.company = this.formData.company,
						obj.startTime = this.formData.startTime,
						obj.endTime = this.formData.endTime,
						obj.placeType = this.formData.placeType,
						obj.level = this.formData.level
					this.$emit('testShow', obj)
				} else if (this.type == 6) {
					obj.dangerDesc = this.formData.dangerDesc,
						obj.community = this.formData.community,
						obj.company = this.formData.company,
						obj.startTime = this.formData.startTime,
						obj.endTime = this.formData.endTime,
						obj.placeType = this.formData.placeType,
						obj.level = this.formData.level
					this.$emit('testShow', obj)
				} else if (this.type == 6.1) { //隐患列表
					obj.community = this.formData.community,
						obj.company = this.formData.company,
						obj.startTime = this.formData.startTime,
						obj.endTime = this.formData.endTime,
						obj.placeType = this.formData.placeType,
						obj.level = this.formData.level
					obj.pageNo = 1
					obj.tyue = 1
					this.$emit('testShowTwo', obj)
				} else if (this.type == 6.2) { //场所列表
					obj.community = this.formData.community,
						obj.startTime = this.formData.startTime,
						obj.endTime = this.formData.endTime,
						obj.placeType = this.formData.placeType,
						obj.placeName = this.formData.industryCategory
					obj.pageNo = 1
					obj.pageSize = 10
					this.$emit('testShowChansuo', obj)
				}
				console.log(obj)

			},
			closeDrawer() {
				this.$refs["showLeft"].close();
			},

			formReset: function(e) {
				console.log('清空数据')
			},
			changeCheckStatus(obj) {
				this.formData.status = obj
			},
			changeplaceStatus(obj) {
				this.formData.placeStatus = obj
			},
			changelevel(obj) {
				this.formData.level = obj
			},
			changecompany(obj) {
				this.formData.company = obj
			},
			changedimension(obj) {
				this.formData.dimension = obj
			},
			changereviewStatus(obj) {
				this.formData.reviewStatus = obj
			},
			changeplaceType(obj) {
				this.formData.placeType = obj
			},
			changecommunity(obj) {
				this.formData.community = obj
			},
			// // 选择日期
			// bindDateChange: function(e) {
			// 	this.start_date = e.target.value

			// },
			// bindDateChange2: function(e) {
			// 	this.end_date = e.target.value;
			// 	this.other = this.end_date;
			// },
			// 获取当前时间
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			getdet() {
				server.queryTreeList().then(res => {
					this.$nextTick(function() {
						console.log(res,'8888888888888888888888888888')
						this.queryTreeList = res.data.result
					});
			
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	/deep/.uni-drawer__content--visible {
		overflow-y: auto;
	}

	/deep/.uni-forms {
		padding-top: 0 !important;
	}

	/deep/.uni-forms-item__box {
		float: left;
		width: 100%;
	}

	.uni-forms-item__label {
		width: 0;
	}

	.uni-form-item .title {
		padding: 20rpx 0;
	}

	/deep/uni-checkbox.checked .uni-checkbox-input {
		background-color: rgb(0, 122, 255) !important;
		border-color: rgb(0, 122, 255) !important;
	}

	/deep/.cu-form-group {
		padding: unset;

		.title {
			text-align: justify;
			padding-right: unset;
			font-size: 15px;
			position: relative;
			height: 30px;
			line-height: 30px;
		}

		uni-input {
			width: 100%;
		}

		uni-picker::after {
			right: 0;
		}
	}

	/deep/.align-center {
		width: 100%;
	}

	.formbox {
		padding: 15px;
		float: left;
		width: 100%;

		.h5 {
			float: left;
			box-sizing: border-box;
			font-size: 18px;
			margin-bottom: 25px;
			font-weight: bold;
			width: 100%;
		}

		.ul {
			margin-bottom: 20px;
			float: left;
			width: 100%;

			.h6 {
				// float: left;
				box-sizing: border-box;
				margin-bottom: 10px;
				font-size: 15px;
				position: relative;
				padding-left: 10px;
				font-weight: bold;
			}

			.h6:before {
				width: 5px;
				content: '';
				height: 21px;
				background-color: #00a4ff;
				display: inline-block;
				border-radius: 7px;
				position: absolute;
				top: 0;
				left: 0;
			}

			.uni-forms-item {
				float: left;
				width: 100%;
			}
		}

	}

	.uni-forms {
		float: left;
	}

	// 时间
	.leave_cont .ul {
		padding-left: 30rpx;
	}

	.leave_cont .ul .li {
		display: flex;
		align-items: center;
		border-bottom: 1px solid #efefef;
	}

	.leave_cont .ul .li text {
		padding: 40rpx 0;
		font-size: 34rpx;
		font-family: '黑体';
	}

	.leave_cont .ul .li .flex1 {
		flex: 1;
		text-align: right;
		padding-right: 25rpx;
		color: #999999;
		font-size: 32rpx;
	}

	.date {
		height: 42rpx;
	}

	.leave_cont .ul .li uni-text {
		padding: 10px 0 !important;
	}

	.uni-label-pointer {
		margin-right: 10px;
	}

	// 时间
	.uni-btn-v {
		// display: flex;
		// margin-top: 20px;
		// position: fixed;
		// bottom: 0;
		box-sizing: border-box;
		width: 100%;

		uni-button {
			// width: 100%;
			border-radius: 30px;
			margin: 10px;
		}

		uni-button:after {
			border: unset;
		}
	}

	/deep/.uni-forms-item__inner {
		padding-bottom: 0;
	}

	.uni-drawer {
		z-index: 999999;
	}
</style>
